import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;


public class BorderLayoutFrame extends JFrame implements ActionListener {

    private static final String[] names = {"Hide North", "Hide South", "Hide Center", "Hide Left", "Hide Right"};
    private JButton[] buttons;
    private BorderLayout layout;
    
    public BorderLayoutFrame(){
	super("BorderLayoutFrame");
	layout = new BorderLayout(20,20);
	setLayout(layout);
	
	buttons = new JButton[names.length];
	
	for(int i = 0 ; i < names.length; i++){
	    buttons[i] = new JButton(names[i]);
	    buttons[i].addActionListener(this);
	}
	
	add(buttons[0],BorderLayout.NORTH);
	add(buttons[1],BorderLayout.SOUTH);
	add(buttons[2],BorderLayout.CENTER);
	add(buttons[3],BorderLayout.EAST);
	add(buttons[4],BorderLayout.WEST);
	
	
    }
    
    @Override
    public void actionPerformed(ActionEvent e) {
	for(JButton button : buttons){
	    if(e.getSource() == button){
		button.setVisible(false);
	    }
	    else{
		button.setVisible(true);
	    }
	    
	    layout.layoutContainer(this.getContentPane());
	}
	
    }

}
